package rs.etf.es.visualization;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;

public class SaveGraphEventHandler implements ActionListener {

    private MainWindow main;

    public SaveGraphEventHandler(MainWindow main) {
	this.main = main;
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
	int retVal = main.getFileChooser().showSaveDialog(main.frmBayesianNetworkSimulator);
	if (retVal == JFileChooser.APPROVE_OPTION) {
	    File selectedFile = main.getFileChooser().getSelectedFile();
	    try {
		AlgorithmController.instance().saveToFile(selectedFile);
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }

}
